
<script setup lang="ts">
import { ref, reactive, inject, onMounted } from 'vue'

import emitter from '@/utils/eventBus'

const showGasDailg = inject('showGasDialog') as (tyep: number, dataId: number) => {}

// props
const props = defineProps({
  dataId: {
    type: Number,
    default: null
  }
})

// 定义变量
const CONum = ref(0)
const O2Num = ref(0)

const position = ref('')
// 定义方法

onMounted(() => {
  emitter.on('COData', showCoInfo)
  emitter.on('O2Data', showO2Info)
  switch (props.dataId) {
  case 2:
    position.value = '42'
    break
  case 3:
    position.value = '43'
    break
  case 6:
    position.value = '46'
    break
  case 7:
    position.value = '47'
    break
  case 8:
    position.value = '48'
    break
  case 51:
    position.value = '31'
    break
  } 
})

// 接收气体数据
const showCoInfo = (COData:any) => {
  let coData = COData.find((item:any) => {
    return (String(item.BarSectionId) + String(item.SensorNum)) === position.value
  })
  // console.log('接收的气体数据信息CCCCCC--------->', coData, position.value)
  CONum.value = coData.Value
}
const showO2Info = (O2Data: any) => {
  let o2Data = O2Data.find((item: any) => {
    return (String(item.BarSectionId) + String(item.SensorNum)) === position.value
  })
  O2Num.value = o2Data.Value
}

// 引入依赖
const showIcon:any = inject('showIcon')
interface alarmDataIntef{
  CO: string,
  O2: string,
  CH4: string,
  smoke: string,
  dust: string,
  infrared: string
}
const alarmData:alarmDataIntef = inject('alarmData') as alarmDataIntef

</script>
<template>
  <el-popover
    placement="top-start"
    :width="154"
    trigger="hover"
  >
    <template #reference>
      <div
        v-show="showIcon.CO || showIcon.O2"
        class="two-item-box first-son"
        @click="showGasDailg(2, props.dataId)"
      >
        <div
          v-show="showIcon.CO"
          :id="(String(CONum) < alarmData.CO) ? '' : (false ? 'gasFirstary' : 'gasSecondary')"
          class="co-box iconfont icon-yiyanghuatan"
        />
        <div
          v-show="showIcon.O2"
          :id="(String(O2Num) > alarmData.O2) ? '' : (false ? 'gasFirstary' : 'gasSecondary')"
          class="o2-box iconfont icon-yangqi"
        />
      </div>
    </template>
    <template #default>
      <div class="pop-box">
        <!-- <div class="info-item">
          <div class="ch4-num info-num">
            89%
          </div>
          <div class="info-name">
            甲烷
          </div>
        </div> -->
        <div
          v-show="showIcon.CO"
          class="info-item"
        >
          <div
            :id="(String(CONum) < alarmData.CO) ? '' : (false ? 'gasFirstary' : 'gasAlarm')"
            class="co-num info-num"
          >
            {{ CONum }}
          </div>
          <div
            
            class="info-name"
          >
            一氧化碳
          </div>
        </div>
        <div
          v-show="showIcon.O2"
          class="info-item "
        >
          <div
            :id="(String(O2Num) > alarmData.O2) ? '' : (false ? 'gasFirstary' : 'gasAlarm')"
            class="smoke-num info-num"
          >
            {{ O2Num }}
          </div>
          <div class="info-name">
            氧气
          </div>
        </div>
        <!-- <div class="info-item">
          <div class="dust-num info-num ">
            32%
          </div>
          <div class="info-name">
            粉尘
          </div>
        </div> -->
      </div>
    </template>
  </el-popover>
</template>

<style lang="scss" scoped>
.two-item-box {
  display: flex;
  justify-content: center;
  width: 68px;
  height: 40px;
  margin-top: 1.6vh;
  margin-left: 0.35vw;
  background: #f8fafd;
  border: 1px solid rgba($color: #000, $alpha: 0%);
  border-radius: 54px;
  box-shadow: 0 4px 8px 0 rgb(166 184 208 / 40%);
  opacity: 1;
  >div {
    width: 24px;
    height: 24px;
    margin-top: 8px;
    line-height: 24px;
    text-align: center;
    background: linear-gradient(180deg, #54aafe 0%, #4482ed 100%);
    border-radius: 24px;
    box-shadow: 0 2px 4px 0 #bbd2ff;
    opacity: 1;
  }
  .o2-box {
    margin-left: 4px;
  }
}
.two-item-box:hover {
  cursor: pointer;
}
.first-son {
  margin-left: 50px;
}
.second-son {
  margin-left: 1192px;
}
.btn-box {
    display: flex;
    margin-left: 30px;

    /* border: 1px solid red; */
    >div {
      width: 44px;
      height: 20px;
      margin-top: 6px;
      font-weight: 600;
      font-size: 14px;
      font-family: PingFang, sans-serif;
      line-height: 20px;
      text-align: center;
      background-clip: text;
    }
    .search-btn {
      color: #2191ff;
    }
    .search-btn:hover {
      cursor: pointer;
    }
    .clear-btn:hover {
      cursor: pointer;
    }
  }
  .icon-divider {
    width: 0 !important;
    height: 12px !important;
    margin-top: 10px !important;
    border: 1px solid #a9aeb8 !important;
  }
  .pop-box {
  .info-item {
    .info-num {
      color: #fff;
      font-family: Ding,sans-serif;
    }
  }
}
</style>
<style lang="scss">
.query-criteria-box {
  display: flex;
  .gas-time {
    width: 100px;

    /* border: 1px solid red; */
  }
  .gas-interval {
    width: 200px;
    margin-left: 20px;

    /* border: 1px solid red; */
  }
  .gas-unit {
    width: 150px;
    margin-left: 20px;

    /* border: 1px solid red; */
  }
}
</style>
